<template>
	<view>
		<view class="ffffff">
			<u-tabs :list="tabs" lineColor="#fe8604" :activeStyle="{
		    color: '#333',
		    fontWeight: 'bold',
		    transform: 'scale(1.05)',
			fontSize:'30rpx'
		}" :inactiveStyle="{
		    color: '#999',
		    transform: 'scale(1)',
			fontSize:'30rpx'
		}" keyName="name" @click="tabclick"></u-tabs>
		</view>
		<view class="mainpadding2">
			<taskList :list="list.data" :clws="clws" @init="init"></taskList>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabsid: 1,
				tabs: [],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				lat:"",
				lng:"",
				isLoad:false,
				clws:false
			}
		},
		onLoad() {
			// #ifdef APP-PLUS
			this.getLocation()
			// #endif
			// #ifdef H5
			this.getrwlx()
			// #endif
		},
		onShow() {
			if(this.isLoad){
				this.init()
			}
		},
		methods: {
			async getLocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						console.log(res, "获取定位成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getrwlx()
					},
					fail(err) {
						uni.hideLoading()
						console.log(err, 23432);
					}
				});
			},
			getrwlx() {
				httpRequest.request('/api/taskcl/taskCategortyIndex', 'GET', {}, false, false, true).then(res => {
					this.tabs = res.data
					this.tabsid = res.data[0].id
					this.init()
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			init(isPage, page) {
				if (!httpRequest.checkIsLogin()) {
					this.list = {
						data:[]
					}
					return false
				}
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					task_category_id:this.tabsid,
					lat:this.lat,
					lng:this.lng,
				}
				let url = '/api/taskcl/taskIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					this.isLoad = true
					if (res.code == 1) {
						this.clws = false
						res.data.data.forEach(item=>{
							this.$set(item,"iszk",false)
						})
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
					if(res.code==-1){
						this.clws = true
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			tabclick(e) {
				this.tabsid = e.id
				this.init()
			}
		}
	}
</script>

<style>

</style>